home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / QuickDraw GX / Programming Stuff / GXEdit Library & Doc / GXEditUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-10  |  3.0 KB  |  164 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:                GXEditUtils.c
  3.     
  4.     Contains:
  5.     
  6.     Written by:        Barton R. House
  7.     
  8.     Copyright:        © 1993 by Apple Computer, Inc., All rights reserved.
  9.     
  10. */
  11.  
  12. #include "GXEdit.h"
  13. #include "GXEditDoc.h"
  14. #include "GXEditDebug.h"
  15. #define _GXEditUtilsPrivate_
  16. #include "GXEditUtils.h"
  17.  
  18. #include "graphics routines.h"
  19. #include "math routines.h"
  20.  
  21. Boolean gxEditSetBitMaskOp(char * src, char * dst, char * mask, long size)
  22. {
  23.     Boolean        modified;
  24.     char        val;
  25.     
  26.     modified = false;
  27.     
  28.     while(size--) {
  29.     
  30.         val = (*dst & ~(*mask)) | (*src & *mask);
  31.         
  32.         if(val != *dst) {
  33.         
  34.             modified = true;
  35.             *dst = val;
  36.             
  37.         }
  38.         
  39.         src++;
  40.         dst++;
  41.         mask++;
  42.         
  43.     }
  44.     
  45.     return(modified);
  46.     
  47. }
  48.  
  49. void gxEditGetBitMaskOp(char * src, char * dst, char * mask, long size, Boolean firstTime)
  50. {
  51.     if(firstTime) {
  52.     
  53.         while(size--) {
  54.             *dst++ = *src++;
  55.             *mask++ = 0xff;
  56.         }
  57.         
  58.     } else {
  59.     
  60.         while(size--) {
  61.         
  62.             if(*src != *dst)
  63.                 *mask &= ~(*src ^ *dst);
  64.             src++;
  65.             dst++;
  66.             mask++;
  67.             
  68.         }
  69.     }
  70. }
  71.  
  72. void gxEditDisposeOffscreen(DocPtr dp)
  73. {
  74.  
  75.     if(dp->offscreenBytes != nil)
  76.         DisposePtr(dp->offscreenBytes);
  77.         
  78.     if(dp->offscreenBitmap != nil)
  79.         GXDisposeShape(dp->offscreenBitmap);
  80.         
  81.     if(dp->offscreenPort != nil)
  82.         GXDisposeViewPort(dp->offscreenPort);
  83.         
  84.     if(dp->offscreenDevice != nil)
  85.         GXDisposeViewDevice(dp->offscreenDevice);
  86.         
  87.     if(dp->offscreenGroup != nil)
  88.         GXDisposeViewGroup(dp->offscreenGroup);
  89.         
  90. }
  91.  
  92.  
  93. void gxEditBuildOffscreen(DocPtr dp)
  94. {
  95.     gxBitmap            bitmapRec;
  96.     long            height;
  97.     long            width;
  98.     long            rowBytes;
  99.     gxPoint            bitmapPos;
  100.     gxMapping            deviceMatrix;
  101.             
  102.     height = dp->viewRect.bottom - dp->viewRect.top;
  103.     width = dp->viewRect.right - dp->viewRect.left;
  104.     rowBytes = (width + 7) / 8;
  105.     rowBytes = (rowBytes + 0x3L) & ~0x3L;
  106.  
  107.     if(dp->offscreenBytes != nil)
  108.         DisposePtr(dp->offscreenBytes);
  109.     
  110.     dp->offscreenBytes = NewPtr(rowBytes * height);
  111.     
  112.     bitmapRec.image = dp->offscreenBytes;
  113.     bitmapRec.width = width;
  114.     bitmapRec.height = height;
  115.     bitmapRec.rowBytes = rowBytes;
  116.     bitmapRec.pixelSize = 1;
  117.     bitmapRec.space = gxIndexedSpace;
  118.     bitmapRec.set = nil;
  119.     bitmapRec.profile = nil;
  120.     
  121.     bitmapPos.x = ff(dp->viewRect.left);
  122.     bitmapPos.y = ff(dp->viewRect.top);
  123.     
  124.     if(dp->offscreenBitmap == nil)
  125.         dp->offscreenBitmap = GXNewBitmap(&bitmapRec, &bitmapPos);
  126.     else
  127.         GXSetBitmap(dp->offscreenBitmap, &bitmapRec, &bitmapPos);
  128.         
  129.     if(dp->offscreenGroup == nil)
  130.         dp->offscreenGroup = GXNewViewGroup();
  131.         
  132.     if(dp->offscreenDevice == nil)
  133.         dp->offscreenDevice = GXNewViewDevice(dp->offscreenGroup, dp->offscreenBitmap);
  134.     else
  135.         GXSetViewDeviceBitmap(dp->offscreenDevice, dp->offscreenBitmap);
  136.         
  137.     if(dp->offscreenPort == nil)
  138.         dp->offscreenPort = GXNewViewPort(dp->offscreenGroup);
  139.     
  140.     ResetMapping(&deviceMatrix);
  141.     MoveMappingTo(&deviceMatrix, ff(-dp->viewRect.left), ff(-dp->viewRect.top));
  142.     GXSetViewDeviceMapping(dp->offscreenDevice, &deviceMatrix);
  143.         
  144. }
  145.  
  146. void gxEditFlushCaches(DocPtr dp)
  147. {
  148.     ParaRec* para = *dp->paragraphs;
  149.     short paraCount = dp->numParagraphs;
  150.  
  151.     while (paraCount--)
  152.     {    LineRec* gxLine = *para->lines;
  153.         short lineCount = para->numLines;
  154.         
  155.         while (lineCount--)
  156.         {    gxLine->dirty = true;
  157.             ++gxLine;
  158.         }
  159.         ++para;
  160.     }
  161. }
  162.  
  163.  
  164.